package common.other;

import org.junit.Test;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

import java.util.ArrayList;
import java.util.List;

public class Finally {


    @Test
    public void testMain() throws  Exception{

//        int b = 1/0;
//        System.out.println("try:"+b);
        try {
            int a = 1/1;
            System.out.println("try:"+a);
            System.exit(0);
            System.out.println("try exit:"+a);
        }
//        catch (Exception e){
//            System.out.println("catch:"+e.getMessage());
//        }
        finally {
            while (true) {
                System.out.println("finally!!!");
                Thread.sleep(1000*2);
            }
        }
    }


    @Test
    public void testMain01() throws  Exception{
        List<Data> list = new ArrayList<>();
        Data data01 = new Data(111,"111");
        Data data02 = new Data(222,"222");
        Data data03 = new Data(333,"333");

        System.out.println(data01);
        System.out.println(data02);
        System.out.println(data03);

        list.add(data01);
        list.add(data02);
        list.add(data03);
        data03.setAaa(457);
        for(Data data:list){
            if(data.equals(data03))
            System.out.println(data);
        }
    }
}

class Data{


    private int aaa;
    private String bbb;


    public Data(int aaa, String bbb) {
        this.aaa = aaa;
        this.bbb = bbb;
    }

    public int getAaa() {
        return aaa;
    }

    public String getBbb() {
        return bbb;
    }

    public void setAaa(int aaa) {
        this.aaa = aaa;
    }

    public void setBbb(String bbb) {
        this.bbb = bbb;
    }


    @Override
    public String toString() {
        return "Data{" +
                "aaa=" + aaa +
                ", bbb='" + bbb + '\'' +
                '}';
    }
}

